package DesignMode.Observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}10:06
 */
public abstract class Subject {
    private List<Observer> observers = new ArrayList<>();

    //增加观察者
    public void Attach(Observer observer){
        observers.add(observer);
    }

    //移除观察者
    public void Detach(Observer observer){
        observers.remove(observer);
    }

    //进行通知
    public void Notify(){
        for (Observer observer : observers) {
            observer.Update();
        }
    }
}
